﻿using System;
using System.Collections.Generic;
using System.Text;

namespace KBEngine.Common
{
    public enum ComponentType
    {
        unknown = 0,
        dbmgr,
        loginapp,
        baseappmgr,
        cellappmgr,
        cellapp,
        baseapp,
        client,
        machine,
        console,
        logger,
        bots,
        watcher,
        interfaces,
        tool,
        end = 15,
    }

    [Flags]
    public enum LogType: uint
    {
        unknown   = 0x00000000,
        PRINT     = 0x00000001,
        ERROR     = 0x00000002,
        WARNING   = 0x00000004,
        DEBUG     = 0x00000008,
        INFO      = 0x00000010,
        CRITICAL  = 0x00000020,
        S_NORM    = 0x00000040,
        S_INFO    = 0x00000080,
        S_ERR     = 0x00000100,
        S_DBG     = 0x00000200,
        S_WARN    = 0x00000400,
    }

    public enum DataType
    {
        STRING = 1,
        UINT8,
        UINT16,
        UINT32,
        UINT64 = 5,
        INT8,
        INT16,
        INT32,
        INT64,
        PYTHON = 10,
        BLOB,
        UNICODE,
        FLOAT,
        DOUBLE,
        VECTOR2 = 15,
        VECTOR3,
        VECTOR4,
        FIXED_DICT,
        ARRAY,
        ENTITYCALL = 20,
    }

    public class Define
    {
        public const int MACHINPS_PORT = 20086;
        public const int CONSOLE_COMMANDCB_MSGID = 65500;
        public const int CONSOLE_LOG_MSGID = 65501; //log 消息
        public const int CONSOLE_WATCHERCB_MSGID = 65502;
        public const int CONSOLE_PROFILECB_MSGID = 65503;

        public static int getDefaultUID()
        {
            int uid = 0;
            try
            {
                string uidStr = Environment.GetEnvironmentVariable("uid");
                uid = int.Parse(uidStr);
            }
            catch
            {
                uid = -1;
            }

            if (uid == -1)
            {
                Logger.LogError("\nUID is not set, The current is -1. Please refer to the http://kbengine.org/docs/installation.html " +
                    "environment variable settings, about UID!\n Or manually specifying the UID parameter.\n");
            }
            return uid;
        }
        public static string getObjAddres(object obj)
        {
            var handle = System.Runtime.InteropServices.GCHandle.Alloc(obj, System.Runtime.InteropServices.GCHandleType.WeakTrackResurrection);
            IntPtr addr = System.Runtime.InteropServices.GCHandle.ToIntPtr(handle);
            return addr.ToString("X");
        }
    }
}
